@layout("/common/_container.html",{js:["/assets/modular/recy/bins/bins.js","/assets/common/libs/rapid-validator/prototype_for_validation.js","/assets/common/libs/rapid-validator/validation_cn.js","/assets/common/libs/rapid-validator/tooltips.js"]}){
<form action="${ctxPath}/bins/uploadBanner" method="post" enctype="multipart/form-data" id="articleForm" lay-filter="articleForm" class="layui-form model-form" style="max-width: 700px;margin: 40px auto;">
<div class="layui-inline">
    <label class="layui-form-label">广告图片或视频</label>
    <div class="layui-input-block">
        <!--<input id="icon" name="icon" placeholder="广告图片" type="hidden" class="layui-input   " />

        <button type="button" class="layui-btn" id="iconUpload">
            <i class="layui-icon">&#xe67c;</i>选择图片
        </button>
        <button id="uploadBtn"  class="layui-btn">上传</button>-->
        <input type="file" name="file" id="uploadFile" />
    </div>
    <div class="layui-input-block">
        <button class="layui-btn">上传</button>
        <button type="button" class="layui-btn" onclick="window.location.href='${ctxPath}/bins'">返回回收箱列表</button>
    </div>
</div>

<table class="layui-table">

    <thead>
    <tr>
        <th>广告图片</th>
        <th>回收箱</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    @for(img in imgWebPathList){
    <tr>
      <td>
          @if(@img.endsWith(".jpg")){
          <img src="${ctxPath}${img}">
          @}else{
          ${@org.apache.commons.io.FilenameUtils.getName(img)}
          @}
      </td>
        <td>
            @for(bins in binsList){
            <input type="checkbox" ${imgMap[img]!=null && strutil.contain(imgMap[img],bins.id+"")?"checked='checked'":""} name="asdf" id="${bins.binsNo}" value="${img},${bins.id}" title="${bins.binsNo}">
            @}
        </td>
    <td><a class="delLink" href="${ctxPath}/bins/delBanner?path=${img}">删除</a></td>
    </tr>
    @}
    </tbody>
</table>
</form>


@}
<script>
    layui.use(['form', 'ax','laydate','admin','upload'], function () {
        var $ = layui.jquery;
        var $ax = layui.ax;
        var form = layui.form;
        var admin = layui.admin;
        var upload = layui.upload;
        // 让当前iframe弹层高度适应
        admin.iframeAuto();
        var iconUploader = upload.render({
            elem:"#iconUpload",
            url:Feng.ctxPath+'/bins/uploadBanner',
            auto:false,
            accept:"file",
            //bindAction:'#saveBtn',
            done:function(res){
                if(res.code==200){
                    Feng.success("上传并保存成功！");
                    admin.putTempData('formOk', true);
                    //关掉对话框
                    admin.closeThisDialog();
                    window.location.reload();
                }else{
                    Feng.error("上传失败！");
                }

            },
            error:function(){

            }
        })
        $("#uploadBtn").click(function(){
            iconUploader.upload();
            window.location.reload();
            return false;
        });
        $(".delLink").click(function(){
            $.getJSON(this.href,function(data){
                if(data.success) {
                    Feng.success("删除成功！");
                    window.location.reload();
                }else{
                    Feng.success(data.message);
                }
            })
            return false;
        })
        form.on("checkbox",function(data){
           console.log(data.value);
           $.getJSON(Feng.ctxPath+"/bins/bindBins?imgAndBins="+data.value+","+data.elem.checked,function(data){

           });
        });
        form.on("submit",function(data){
            var uploadFileName = $("#uploadFile").val();
            if(uploadFileName==""){
                Feng.success("请选择需要上传的图片或者视频")
                return false;
            }else{
                var number = uploadFileName.lastIndexOf(".");
                var ext = uploadFileName.substring(number+1,uploadFileName.length);
                console.log("扩展名："+ext);
                var searchString = "jpg,png,bmp,svg,mp4";
                if(searchString.indexOf(ext)<0){
                    Feng.error("只支持以下格式："+searchString);
                    return false;
                }
            }
            return true;
        })
    });
</script>